<?php
/**
  * LoginController.php
  *
  * This is not a freeware, use is subject to license terms
  * @author CLOUD DEV TEAM
  * 
  */
class IndexController extends Controller
{
	public function __construct()
	{
		$this->lang = self::getLang( array( 'Common' , 'Login' ) );
		parent::__construct();
	}
	
	/**
	 * 登录
	 */
	public function run()
	{
		if( $this->userInfo['userId'] )
		{
			$userModel = User::getInstance();
			$userInfo = $userModel->getOne( array( 'uid' => $this->userInfo['userId'] ) );
			if ( $userInfo['picture_address'] && file_exists( ATTACHMENT . $userInfo['picture_address'] ) )
			{
				$indexPicture = ATTACHMENTURL . $userInfo['picture_address'];
				$picInfo = getimagesize( ATTACHMENT . $userInfo['picture_address'] );
			}
			else
			{
				$pictureModel = Picture::getInstance();
				$pictureList = $pictureModel->select( array( 'uid' => $this->userInfo['userId'] , 'flag' => 0 ) );
				if ( $pictureList )
				{
					$randIndex = array_rand( $pictureList );
					$indexPicture = ATTACHMENT . $pictureList[$randIndex]['picture_address'];
					if ( file_exists( ATTACHMENT . $pictureList[$randIndex]['picture_address'] ) )
						$picInfo = getimagesize( ATTACHMENT . $pictureList[$randIndex]['picture_address'] );
				}
				else
				{
					$indexPicture = IMAGEURL . 'noPicture.jpg';
				}
			}
			
			if ( $picInfo )
			{
				$width = $picInfo[0] > 960 ? 960 : '';
				$height = $picInfo[1] > 600 ? 600 : '';
			}
			
		}
		else
		{
			$indexPicture = IMAGEURL . 'noPicture.jpg';
		}
		
		$this->viewModel->tplAssign(
			array(
				'indexPicture',
				'width',
				'height',
			),
			array(
				$indexPicture,
				$width,
				$height,
			)
		);
		$this->viewModel->display( 'index.htm' );
	}
}